package com.koocloud.electroplatemanage.controller;

import com.koocloud.electroplatemanage.common.pojo.ResponseTemplate;
import com.koocloud.electroplatemanage.pojo.ProductionPlan;
import com.koocloud.electroplatemanage.service.ProductionPlanService;
import org.apache.commons.lang3.StringUtils;
import org.apache.ibatis.annotations.Param;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * @program: Information_platform
 * @description: 生产计划控制层
 * @author: xxc
 * @create: 2020-11-02 18:30
 */
@RestController
@RequestMapping("/productionplan")
public class ProductionPlanController {
    static Logger log = Logger.getLogger("productionplan");

    @Autowired
    ProductionPlanService productionPlanService;

    /**
     *@Description: 全表查询
     *@Param: [page, limit, productionPlan] 开始时间  结束时间  数据库按开工时间 start_date  查询  不传就查当天，传按时间段
     *@return: com.koocloud.electroplatemanage.common.pojo.ResponseTemplate
     *@Author: xxc
     *@date: 2020/11/2
     */
    @RequestMapping(value = "/selectAllData", method = RequestMethod.POST, name = "全表查询")
    public ResponseTemplate selectAllData(String page, String limit,String beginTime,String endTime, ProductionPlan productionPlan) {
        //分页参数为空则赋值0
        if (!StringUtils.isNotEmpty(page)) {
            page = "0";
        }
        if (!StringUtils.isNotEmpty(limit)) {
            limit = "0";
        }
        //查询所有记录 分页
        return productionPlanService.selectAllData(page,limit,beginTime,endTime,productionPlan);

    }
    /**
     *@Description:通过主表id查询数据(主表点击生产计划按钮时跳生产计划新增时调用)
     *@Param: [id]
     *@return: com.koocloud.electroplatemanage.common.pojo.ResponseTemplate
     *@Author: zww
     *@date: 2020/11/2
     */
    @RequestMapping(value = "/selectByIncomePartId", method = RequestMethod.POST, name = "主表id查询数据")
    public ResponseTemplate selectByIncomePartId(String orderNumber) {
        //主表id查询数据
        return productionPlanService.selectByIncomePartId(orderNumber);
    }

    @RequestMapping(value = "/insert", method = RequestMethod.POST, name = "新增一条数据")
    public ResponseTemplate insert(HttpServletRequest request, @RequestBody ProductionPlan productionPlan) {
        String userId = request.getHeader("userId");
        //插入一条记录
        return productionPlanService.insert(productionPlan,userId);
    }


    @RequestMapping(value = "/delete", method = RequestMethod.POST, name = "逻辑删除一条记录")
    public ResponseTemplate delete(@RequestParam(name="id") String id,@RequestParam(name="incomePartJudgeId") String incomePartJudgeId,@RequestParam(name="deleteFlag") String deleteFlag) {
        //逻辑删除一条记录
        return productionPlanService.delete(id,incomePartJudgeId,deleteFlag);
    }



    /**
     *@Description: 修改一条记录
     *@Param: [productionPlan]
     *@return: com.koocloud.electroplatemanage.common.pojo.ResponseTemplate
     *@Author: xxc
     *@date: 2020/11/2
     */
    @RequestMapping(value = "/update", method = RequestMethod.POST, name = "修改一条记录")
    public ResponseTemplate update(HttpServletRequest request,@RequestBody ProductionPlan productionPlan) {
        String userId = request.getHeader("userId");
        //修改一条记录
        return productionPlanService.update(productionPlan,userId);
    }
}
